package pro.model.tests;

import java.util.*;
import junit.framework.TestCase;
import pro.model.core.*;

/**
 * @author  sangwo.y
 */
public class PileTest extends TestCase {
	
	private Pile pile;
	private Card KH;
	private Card AH;
	private Card QH;
	private Card KD;
	private Card KS;
	private Card JS;
	private Card TenD;
	private Card NineC;
	private List<Card> cards;
	
	protected void setUp() throws Exception {
		super.setUp();
		pile = new Pile(1);
		cards = new ArrayList<Card>();
		NineC = new Card(Card.Suit.Club, Card.Value.Nine);
		TenD = new Card(Card.Suit.Diamond, Card.Value.Ten);
		KH = new Card(Card.Suit.Heart, Card.Value.King);
		KS = new Card(Card.Suit.Spade, Card.Value.King);
		JS = new Card(Card.Suit.Spade, Card.Value.Jack);
		AH = new Card(Card.Suit.Heart, Card.Value.Ace);
		QH = new Card(Card.Suit.Heart, Card.Value.Queen);
		KD = new Card(Card.Suit.Diamond, Card.Value.King);	
		cards.add(KD);  cards.add(AH);  cards.add(KS);  cards.add(QH);	
	}
	
	public PileTest(String name) {
		super(name);
	}
	
	public void testPile() {
		assertEquals("testPile failed", 0, pile.size());
	}
	
	public void testGetPileId() {
		assertEquals("testGetPileId failed", 1, pile.getPileId());
	}
	
	public void testPop() {		
		System.out.println("---- testPop -------");
		pile.pushInternal(QH); pile.pushInternal(KD);
		System.out.println(pile);
		assertTrue("testPop(Card) failed", (pile.pop()).equals(KD));
		try {
			pile.pop(); pile.pop();	fail();
		} catch (Exception e) {}
		System.out.println(pile);
		pile.pushInternal(cards);
		System.out.println(pile);
		assertTrue("testPop(List<Card>) failed", checkPopedList(pile.pop(3)));
		System.out.println(pile);
		try {
			pile.pop(2); fail();
		} catch (Exception e) {}
		
		pile.clear();
		System.out.println(pile);
		pile.pushInternal(AH); pile.pushInternal(KD); pile.pushInternal(QH);
		System.out.println(pile);
		assertNull("testPop(List) failed", pile.pop(2));
		System.out.println(pile);
		System.out.println("---- testPop/E -------");		
	}
	
	private boolean checkPopedList(List<Card> cl) {
		if (  cl.get(0).equals(AH) && cl.get(1).equals(KS) && cl.get(2).equals(QH)) {
			return true; 
		} else {
			return false;
		}
	}
	
	public void testPush() {
		System.out.println("---- testPush -------");
		System.out.println(pile);
		pile.push(QH); 
		assertNull("testPush failed", pile.push(QH));
		assertNull("testPush failed", pile.push(KD));
		assertNotNull("testPush failed", pile.push(JS));
		System.out.println(pile);
		
		assertFalse("testPust failed", pile.push(cards));
		System.out.println(pile);
		cards.clear();
		cards.add(TenD); cards.add(NineC);
		assertTrue("testPust failed", pile.push(cards));
		System.out.println(pile);
		System.out.println("---- testPush/E -------");
	}

}
